package com.socio.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Day implements Serializable {
	
	private static final long serialVersionUID = -2804360155581482358L;

	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private User user;
	
	@Persistent(mappedBy="day")
	@Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="type asc, change asc"))
	private List<Event> events = new ArrayList<Event>(0);
	
	@Persistent
	private long startTime;
	
	@Persistent
	private long quickScore;

	public Day() {
	}
	
	public Day(long startTime) {
		this.startTime = startTime;
	}
	
	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Event> getEvents() {
		return events;
	}

	public void setEvents(List<Event> events) {
		this.events = events;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public long getQuickScore() {
		return quickScore;
	}

	public void setQuickScore(long quickScore) {
		this.quickScore = quickScore;
	}

	public void incrementQuickScore() {
		this.quickScore++;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (startTime ^ (startTime >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Day other = (Day) obj;
		if (startTime != other.startTime)
			return false;
		return true;
	}
	
}
